package com.linbit.crypto;

import com.linbit.linstor.LinStorException;

/**
 * Conceals the exact length of a plaintext message
 *
 * Using CFB mode with no padding, encryption does not change the length of a plaintext message,
 * therefore, the ciphertext leaks information about the length of the plaintext that was encrypted.
 *
 * The conceal(...) method encodes a plaintext message in one or multiple blocks of a fixed length,
 * so that the exact length of the plaintext message will be concealed after the message has been
 * encrypted.
 * The retrieve(...) method decodes the original plaintext message from the data generated by the
 * conceal(...) method.
 *
 * @author Robert Altnoeder &lt;robert.altnoeder@linbit.com&gt;
 */
public interface LengthPadding
{
    /**
     * Encodes a plaintext message to enable concealing its exact length when encrypting the message
     *
     * @param data Plaintext message
     * @return Block-wise encoded data containing the plaintext message
     */
    byte[] conceal(byte[] data)
        throws LinStorException;

    /**
     * Decodes the original plaintext message from data generated by the conceal(...) method
     *
     * @param data Encoded data generated by the conceal(...) method
     * @return Original plaintext message
     */
    byte[] retrieve(byte[] data)
        throws LinStorException;
}
